"""
@author: Lin
@time: 2022/7/15 12:40
谢尔宾斯基三角形
等边三角形边长a, 中轴线长度a√3/2
重心分割中轴线分成两个线段长度分别是 a√3/3,a√3/6
"""

import turtle as t
import math


def draw_triangle(p, x, y, size, direction='down'):
    p.up()
    p.goto(x, y)
    # down
    p.setheading(270)
    p.forward(math.sqrt(3) * size / 3)
    p.setheading(120)
    p.down()
    p.forward(size)
    p.right(120)
    p.forward(size)
    p.right(120)
    p.forward(size)


if __name__ == '__main__':
    pen = t.Pen()
    x = y = 0
    size = 100
    draw_triangle(pen, x, y, size)
    draw_triangle(pen, -size / 2, -size / math.sqrt(12), size / 2)
    draw_triangle(pen, x, 2 * size / math.sqrt(12), size / 2)
    draw_triangle(pen, size / 2, -size / math.sqrt(12), size / 2)
